package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.ShiroUtils;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.entity.CoreServiceObject;
import com.corechina.apex_osswords.service.ICoreServiceObjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 服务对象表 前端控制器
 * </p>
 *
 * @author fyh
 * @since 2023-02-15
 */

@Api(tags = "服务对象")
@RestController
@RequestMapping("/core/serviceObject")
public class CoreServiceObjectController {

    @Autowired
    private ICoreServiceObjectService iCoreServiceObjectService;

    @SysLog("新增服务对象")
    @ApiOperation("新增")
    @PostMapping("/add")
    public Response add(@RequestBody CoreServiceObject coreServiceObject) {
        coreServiceObject.setEnterpriseId(ShiroUtils.getEnterpriseId());
        if (iCoreServiceObjectService.save(coreServiceObject)) {
            return Response.ok();
        }
        return Response.error();
    }

    @SysLog("编辑服务对象")
    @ApiOperation("编辑")
    @PutMapping("/update")
    public Response update(@RequestBody CoreServiceObject coreServiceObject) {
        return iCoreServiceObjectService.update(coreServiceObject);
    }

    @ApiOperation("列表")
    @GetMapping("/getList")
    public Response getList(Integer isDel, String name, Integer pageIndex, Integer pageSize) {
        return iCoreServiceObjectService.getList(isDel, name, pageIndex, pageSize);
    }

    @ApiOperation("详情")
    @GetMapping("/getOne")
    public Response gteOne(Integer id) {
        return Response.ok(iCoreServiceObjectService.getById(id));
    }

}

